'use strict';

const Controller = require('egg').Controller;

class MessageController extends Controller {
  async getInfoList() {
    let result = await this.ctx.service.message.getInfoList();
    console.log(result + "111");
    if (result) {
      this.ctx.body = {
        code: 20000,
        data: result
      }
    }
    else {
      this.ctx.body = {
        code: 50000,
        data: '数据获取失败'
      }
    }
  }
  async createMessage() {
    try {
      const body = this.ctx.request.body;
      console.log(body);
      await this.service.message.createMessage(body);
      this.ctx.body = {
        code: 20000,
        message: true
      }
    } catch (error) {
      this.ctx.body = {
        code: 30000,
        data: "发表失败"
      }
    }
  }
  async getMessageDetail() {
    const { ctx } = this;
    console.log('方式一：query', ctx.query);
    const user_id = ctx.query.user_id;
    // console.log(user_id);
    try {
      let IdMessagedata = await this.ctx.service.message.getMessageDetail(user_id);
      this.ctx.body = {
        code: 20000,
        message: true,
        data: IdMessagedata,
      }
    } catch (error) {
      this.ctx.body = {
        code: 30000,
        message: false,
      }
    }
  }
  async deleteIdMessage() {

    const id=this.ctx.params.id;
    // const { ctx } = this;
    // console.log(ctx.query);
    // console.log(6666);
    // const id = ctx.query.id;
    console.log(id+"333");
    try {
      await this.ctx.service.message.deleteIdMessage(id);
      this.ctx.body = {
        code: 20000,
        message: true
      }

    } catch (error) {
      this.ctx.body = {
        code: 30000,
        message: false
      }
    }
  }
}

module.exports = MessageController;
